#include "isr.h"
#include "idt.h"
#include "i386.h"
#include "klib.h"

void aux(int index,unsigned int isr, unsigned short segselector, unsigned short attr)
{
	idt[index].offset_0_15 = (unsigned short) (isr & (unsigned int) 0xFFFF); 
	idt[index].segsel = (unsigned short) segselector; 
	idt[index].attr = (unsigned short) attr; 
	idt[index].offset_16_31 = (unsigned short) (isr >> 16 & (unsigned int) 0xFFFF);
	
}

void inicializar_idt() {
	aux(0,(unsigned int)(&_isr0),0x0008,0x8F00);
	aux(1,(unsigned int)(&_isr1),0x0008,0x8F00);
	aux(2,(unsigned int)(&_isr2),0x0008,0x8E00);
	aux(3,(unsigned int)(&_isr3),0x0008,0x8F00);
	aux(4,(unsigned int)(&_isr4),0x0008,0x8F00);
	aux(5,(unsigned int)(&_isr5),0x0008,0x8F00);
	aux(6,(unsigned int)(&_isr6),0x0008,0x8F00);
	aux(7,(unsigned int)(&_isr7),0x0008,0x8F00);
	aux(8,(unsigned int)(&_isr8),0x0008,0x8F00);
	aux(9,(unsigned int)(&_isr9),0x0008,0x8F00);
	aux(10,(unsigned int)(&_isr10),0x0008,0x8F00);
	aux(11,(unsigned int)(&_isr11),0x0008,0x8F00);
	aux(12,(unsigned int)(&_isr12),0x0008,0x8F00);
	aux(13,(unsigned int)(&_isr13),0x0008,0x8F00);
	aux(14,(unsigned int)(&_isr14),0x0008,0x8F00);
	aux(15,(unsigned int)(&_isr15),0x0008,0x8F00);
	aux(16,(unsigned int)(&_isr16),0x0008,0x8F00);
	aux(17,(unsigned int)(&_isr17),0x0008,0x8F00);
	aux(18,(unsigned int)(&_isr18),0x0008,0x8F00);
	aux(19,(unsigned int)(&_isr19),0x0008,0x8F00);
	
	aux(32,(unsigned int)(&_isrReloj),0x0008,0x8F00);	
	aux(33,(unsigned int)(&_isrTeclado),0x0008,0x8F00);
	aux(88,(unsigned int)(&_isr88),0x0008,0xEE00); // pregunta 9:  8E00 tiene priv 0 , entonces ocurre GP fault   porque no se puede saltar directamente a otro nivel
	aux(89,(unsigned int)(&_isr89),0x0008,0xEE00); //
	
	
}

idt_entry idt[255];

idt_descriptor IDT_DESC = {sizeof(idt)-1, (unsigned int)&idt};


